﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX.EHR.Library;
using ZX.BLL;
using ZX.Common;
using System.Data;
using ZX.SPL.ORM;
using System.Reflection;


namespace ZX.BLL.ClientMobi.Message
{
    public class BridgeReplyDefault : MessagePlyBase
    {
        public override int Save(object o1, object o2)
        {
            return base.Save(o1, o2);
        }

        public override int Save(IDictionary<string, object> paramsList)
        {
            //tabTemp = new DAL.DBExtend.DbSql().ExecuteQuery("select CodeNO From Code_BaseInfo where CodeName='反馈建议'");


            StringBuilder sqlCommandBuilder = new StringBuilder();
            sqlCommandBuilder.Append("NEWID(),");
            if (paramsList.Count > 0)
            {
                if (paramsList.ContainsKey("ID"))
                {
                    sqlCommandBuilder.AppendFormat("'{0}',", paramsList["ID"].ToString());
                }
                if (paramsList.ContainsKey("UserID"))
                {
                    sqlCommandBuilder.AppendFormat("'{0}',", paramsList["UserID"].ToString());
                }
                if (paramsList.ContainsKey("Content"))
                {
                    sqlCommandBuilder.AppendFormat("'{0}',", paramsList["Content"].ToString());
                }
                if (paramsList.ContainsKey("ReplyTime"))
                {
                    sqlCommandBuilder.AppendFormat("'{0}',", Convert.ToDateTime(paramsList["ReplyTime"]));
                }
                if (paramsList.ContainsKey("IsRead"))
                {
                    sqlCommandBuilder.AppendFormat("{0},", int.Parse(paramsList["IsRead"].ToString()));
                }
                if (paramsList.ContainsKey("ChangeType"))
                {
                    sqlCommandBuilder.AppendFormat("{0},", int.Parse(paramsList["ChangeType"].ToString()));
                }
                //DeptDescription
                if (paramsList.ContainsKey("DeptDescription"))
                {
                    sqlCommandBuilder.AppendFormat("'{0}',", paramsList["DeptDescription"].ToString());
                }
            }
            string overridResult = sqlCommandBuilder.ToString();
            overridResult = overridResult.Substring(0, overridResult.Length - 1);


            string sqlInit = "insert into MsgReply ([ID]  ,[MsgID]  ,[UserID]  ,[Content]  ,[ReplyTime]  ,[IsRead], [ChangeType], [DeptDescription]) values (" + overridResult + ")";

            //throw new Exception("" + sqlInit);

            return new DAL.DBExtend.DbSql().ExecuteScalar(sqlInit);
        }

        public override object GetListByTSQL(IDictionary<string, object> paramsList)
        {
            DataTable table = new DataTable();
            if (paramsList.ContainsKey("sql"))
            {
                var exeAction = "";
                var sqlString = paramsList["sql"].ToString();
                if (paramsList.ContainsKey("acrtion"))
                {
                    exeAction = paramsList["acrtion"].ToString();
                }

                if (!string.IsNullOrEmpty(exeAction) && exeAction == "ExecuteScalar")
                {
                    return new DAL.DBExtend.DbSql().ExecuteScalar(sqlString);
                }
                else
                {
                    table = new DAL.DBExtend.DbSql().ExecuteQuery(sqlString);
                }

                
            }

            return table;
        }

        public override void ReplyMsg()
        {
            base.ReplyMsg();
        }

        public override string GetList()
        {
            return base.GetList();
        }


    }
}
